package mn.slide.laborberlin.main;

import mn.slide.laborberlin.tabgroup.HomeGroupActivity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class HomeActivity extends Activity implements OnClickListener
{
	private ListView	listV;
	private Button		b1;
	private Button		b2;
	private Button		b3;
	private Button		b4;
	private String[]	mStrings	= {};

	EditText			search_edt;

	@Override
	protected void onCreate( Bundle savedInstanceState )
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
		listV = (ListView) findViewById(R.id.main_list);
		View footerView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.home_item, null, false);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings);

		listV.addFooterView(footerView);
		listV.setAdapter(adapter);
		b1 = (Button) findViewById(R.id.b1);
		b2 = (Button) findViewById(R.id.b2);
		b3 = (Button) findViewById(R.id.b3);
		b4 = (Button) findViewById(R.id.b4);
		b1.setOnClickListener(this);
		b2.setOnClickListener(this);
		b3.setOnClickListener(this);
		b4.setOnClickListener(this);
		search_edt = (EditText) findViewById(R.id.search_edt);
		search_edt.setOnKeyListener(new OnKeyListener()
		{
			public boolean onKey( View v , int keyCode , KeyEvent event )
			{
				// If the event is a key-down event on the "enter" button
				if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER))
				{
					String k = search_edt.getText().toString();
					if (k.length() > 0)
					{
						EditText searchbox = (EditText) v;
						InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
						imm.hideSoftInputFromWindow(searchbox.getWindowToken(), 0);
						Intent intent = new Intent(HomeActivity.this, SearchActivity.class);
						intent.putExtra("searchTxt", k);
						HomeGroupActivity.group.goTo(intent);

					}
					return true;
				}
				return false;
			}
		});
	}

	@Override
	public void onClick( View v )
	{
		// TODO Auto-generated method stub
		switch (v.getId())
		{
			case R.id.b1:
				final Intent intent = new Intent(HomeActivity.this, LeistungsverszeichnisActivity.class);
				b1.postDelayed(new Runnable()
				{

					@Override
					public void run()
					{
						HomeGroupActivity.group.goTo(intent);
					}
				}, 300);
				break;
			case R.id.b2:
				Intent intent1 = new Intent(HomeActivity.this, AnsprechpartnerActivity.class);

				HomeGroupActivity.group.goTo(intent1);
				break;
			case R.id.b3:
				Intent intent2 = new Intent(HomeActivity.this, QualitActivity.class);
				HomeGroupActivity.group.goTo(intent2);
				break;
			case R.id.b4:
				Intent intent3 = new Intent(HomeActivity.this, ImpressumActivity.class);

				HomeGroupActivity.group.goTo(intent3);
				break;
			default:
				break;
		}

	}
}
